import api from '@/api'
export default context => ({
  namespaced: true,
  state: {
    // 字典数据
    dicts: [],
    // 请求队列
    fetchList: [],
    //科室信息
    wareList: [],
  },
  actions: {
    /**
     * @description 获取字典
     * @param {Object} vuex context
     * @param {String} name 字典名称
     */
    get ({ state }, name) {
      const dict = state.dicts.find(e => e.name === name)
      if(!dict){
      }
      return (dict && dict.value) || []
    },

    /**
     * @description 加载一个字典
     * @param {Object} vuex context
     * @param {String} name 字典名称
     */
    fetch (payload, name = '') {
      payload.commit('fetchListPush', name)
      doFetch(payload)
    }
  },
  mutations: {
    /**
     * @description 设置字典
     * @param {Object} vuex context
     * @param {Object} payload {String} name 字典名称
     * @param {Object} payload {Array} value 字典数据
     */
    set (state, { name = '', value = [] } = {}) {
      const dictIndex = state.dicts.findIndex(e => e.name === name)
      if (dictIndex < 0) {
        state.dicts.push({ name, value })
      } else {
        state.dicts.splice(dictIndex, 1, { name, value })
      }
    },
    fetchListPush (state, item) {
      state.fetchList.push(item)
    },
    fetchListClean (state) {
      state.fetchList = []
    }
  }
})
